package pl.zuiol.games.poker.util;

import java.io.Serializable;

/**
 * User: Damian
 * Date: 15.05.11
 * Time: 22:31
 */
public class Card implements Comparable<Card>, Serializable{

    private Rank rank;
    private Suit suit;

    public Card(Rank rank, Suit suit){
        this.rank = rank;
        this.suit = suit;
    }

    @Override
    public String toString(){
        return rank.toString() + " of " + suit.toString();
    }

    public Rank getRank(){
        return  this.rank;
    }

    public Suit getSuit(){
        return this.suit;
    }

    public int compareTo(Card cardToCompare){
        return this.getRank().ordinal() - cardToCompare.getRank().ordinal();
    }

    @Override
    public int hashCode(){
        final int NUMBER = 17;
        int result  = this.getRank().ordinal() * NUMBER + this.getSuit().ordinal();
        return result;
    }

    @Override
    public  boolean equals(Object obj){
        if(obj == null)
            return false;
        if(obj == this)
            return true;
        if(getClass() != obj.getClass())
            return false;
        final Card someCard = (Card)obj;
        if(someCard.getRank() == this.getRank() && someCard.getSuit() == this.getSuit())
            return true;
        else return false;
    }
}
